<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            var params = getParams();
            if (params.strategycommentId) {
                $.get("/strategycomment/" + params.strategycommentId, function (data) {
                    //点评作者id
                    var authorId = data.user.id;
                    //登录的user
                    var user = JSON.parse(sessionStorage.getItem("user"));

                        $(".comment").renderValues(data,{
                            //图片回显
                            getImage:function (item, value) {
                                //把图片的地址切分
                                var url = value.split(";");
                                //分割时多了一个,长度要减一
                                for (var i=0;i<url.length-1;i++)
                                {
                                    $(item).append("<li><img class='comment-img' src='"+url[i]+"'></img></li>")
                                }
                            },
                            //星级评价回显
                            getStar:function (item, value) {
                                var dark = 5 - value;
                                for (var i=0;i<value;i++){
                                    $(item).append("<i class=\"fa fa-star\"></i>")

                                }
                                if(dark > 0){
                                    for (var i=0;i<dark;i++){
                                        $(item).append("<i class=\"fa fa-star-o\"></i>")

                                    }
                                }
                            },
                            getHref:function (item, value) {
                                var href = $(item).attr("href");
                                $(item).attr("href",href+value);
                            }
						});

                        //查询是否关注
                        if (user){
                            $.get('/users/'+user.id+'/'+authorId,function (data) {
                                if (user.id == authorId){
                                    $('#followBtn').html('自己');
                                }else {
                                    if (data){
                                        $('#followBtn').html('取关');
                                    } else {
                                        $('#followBtn').html('关注');
                                    }
                                }
                            });
                        } else {
                            $('#followBtn').html('关注');
                        }

                        //关注按钮点击事件
                        $('#followBtn').click(function () {
                            if (user){
                                if (user.id == authorId){
                                    $(document).dialog({
                                        type: 'notice',
                                        infoText: '关注自己干哈?',
                                        autoClose: 1000,
                                        position: 'center'  // center: 居中; bottom: 底部
                                    });
                                } else{
                                    if ($('#followBtn').html()=='取关') {
                                        $("#followBtn").html("关注");
                                        $(document).dialog({
                                            type: 'notice',
                                            infoText: '取消关注√',
                                            autoClose: 1000,
                                            position: 'center'  // center: 居中; bottom: 底部
                                        });
                                        $.ajax({
                                            url:"/users/"+user.id+"/"+authorId ,
                                            method:"delete"
                                        })
                                    }else {
                                        $('#followBtn').html('取关');
                                        $(document).dialog({
                                            type: 'notice',
                                            infoText: '关注√',
                                            autoClose: 1000,
                                            position: 'center'  // center: 居中; bottom: 底部
                                        });
                                        $.ajax({
                                            url:"/users/"+user.id+"/"+authorId ,
                                            method:"post"
                                        });
                                    }
                                }
							} else {
                                window.location.href='login.html';
							}

                        });
                        //图片点击效果
                        $(".comment-img img").click(function () {
                            $(document).dialog({
                                titleShow: false,
                                overlayClose: true,
                                content: '<div style="text-align: center;"><img width="100%" src="' + $(this).attr('src') + '"></div>'
                            });
                        });

                    });
					//子评论回显
					$.get("/strategydoublecomment/"+params.strategycommentId,function (data) {
                        $("#comment").renderValues({list:data},
							{
                                getHreff:function (item, value) {
                                    var href = $(item).attr("href");
                                    $(item).attr("href",href + value);

                                // console.log(href + value);
                            }
                        })
                })
            }
            //叠加评论按钮点击事件
            $("#commentTarget").click(function () {
                window.location.href = "/mine/addStrategyComment.html?strategycommentId=" + params.strategycommentId;
            })



            })
		</script>
	</head>

	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:history.go(-1);">
						<span><i class="fa fa-chevron-left "></i></span>
					</a>
				</div>
				<div class="col">
					<span>点评详情</span>
				</div>
				<div class="col"></div>
			</div>
		</div>

			<div class="comment">
				<div class="container ">
					<div class="row">
						<div class="col-2 comment-head">
							<a href="../userProfiles.html?id=" render-key="user.id" render-fun="getHref">
								<img class="rounded-circle" render-src="user.headImgUrl">
							</a>
							<button class="btn btn-success" id="followBtn"></button>
						</div>
						<div class="col">
							<span class="comment-star"  render-key="starNum" render-fun="getStar"></span>

							<span class="comment-date" render-html="commendTime"></span>
							<div class="comment-content">
								<p render-html="content"></p>
							</div>
							<ul class="comment-img" render-key="imgUrls" render-fun="getImage">

							</ul>

							<div class="comment-link">
								<a href="../strategyCatalogs.html?strategyId=" render-key="strategy.id" render-fun="getHref">
									<img  render-src="strategy.coverUrl"> <span render-html="strategy.title"></span>
									<i class="fa fa-angle-right fa-2x"></i>
								</a>
							</div>
						</div>
					</div>
				</div>
				<div class="count d-flex justify-content-between">
						<div class="p-2">评论<span render-html="commentNum"></span></div>
						<div class="p-2">赞<span >0</span></div>
				</div>
			</div>
		
			<div id="comment">

				<div render-loop="list">
					<div class="container row comment">
						<div class="col-2 comment-head">
							<a href='../userProfiles.html?id=' render-key="list.user.id" render-fun="getHreff">
								<img class="rounded-circle"
									 render-src="list.user.headImgUrl">
							</a>
						</div>
						<div class="col comment-right">
							<p class="authorName"><span render-html="list.user.nickName"></span>
								<span class="comment-date" render-html="list.commendTime"></span>
							</p>

							<div class="comment-content">
									<p render-html="list.content"></p>
							</div>
							<!--<div class="d-flex icon">
								<a href="mine/strategyComment.html" >
									<i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
									<i class="fa fa-thumbs-o-up" > <span >0</span> </i>
								</a>
							</div>-->

						</div>
					</div>

				</div>
			</div>

		<div class="operation">
			<div class="d-flex justify-content-between">
				<div class="p-2" id="commentTarget"><i class="fa fa-commenting-o"></i> 添加你的评论</div>
				<div class="p-2"><i class="fa fa-star-o"></i> 收藏</div>
			</div>
		</div>
		
	

</body>
</html>